const vm = new Vue({
    el: '#main',
    data: {
        tel: '',
        code: '',
        authCodeText: '获取验证码',
        getAble: false,
        submitAble: false,
    },
    methods: {
        countDown,
        keyUp,
        submit,
    },
});

function apiready() {
    fxj.fixLayout();
}

async function countDown() {
    let s = 60;
    let id = 0;
    const down = () => {
        id = setTimeout(() => {
            vm.getAble = false;
            s--;
            vm.authCodeText = `${s}s后重发`;
            if (s > 0) {
                down();
            }
            else {
                vm.getAble = true;
                vm.authCodeText = `重新获取验证码`;
            }
        }, 1000);
    };
    down();
    const result = await fxj.api.getAuthCode(vm.tel);
    if (!result) {
        clearTimeout(id);
        s = 0;
    }
}

function keyUp() {
    vm.getAble = vm.tel.length >= 11;
}

async function submit() {
    if (!(vm.code && vm.tel)) {
        toast('请填写手机号,验证码');
        return;
    }
    const result = await ajax({
        url: 'home/userLogin/supplementPhone',
        data: {
            phone: vm.tel,
            code: vm.code,
        },
    });
    if (result.err !== 0) {
        toast(result.msg);
    }
    else {
        closeToWin();
    }
}